package com.kmgames.ballsengine.models;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g3d.model.still.StillModel;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.kmgames.ballsengine.rendering.Renderable;

public class Model implements Renderable {
	protected StillModel model;
	protected Fixture physicsFixture;
	private Vector3 position = new Vector3(0, 0, 0);

	public Model(StillModel model, Fixture fixture) {
		this.model = model;
		this.physicsFixture = fixture;
	}

	public Vector3 getPosition() {
		return position;
	}

	public void render() {
		updatePosition();

		Gdx.gl10.glPushMatrix();
		Gdx.gl10.glTranslatef(position.x, position.y, position.z);
		model.render();
		Gdx.gl10.glPopMatrix();
	}

	@Override
	public void renderWithShaders() {
		updatePosition();

		throw new RuntimeException("Not implemented.");
	}

	private void updatePosition() {
		if (physicsFixture != null) {
			position.x = physicsFixture.getBody().getPosition().x;
			position.y = physicsFixture.getBody().getPosition().y;
		}
	}
}
